﻿using Microsoft.AspNetCore.Mvc;
using BCCommon;
using BCDto.OA.Attendance.AttendanceClass;
using BCService.OA.Attendance.AttendanceClass;
using BlackCoffeeRESTful.Configs;

namespace BlackCoffeeRESTful.Controllers.Management.OA.Attendance
{
    /// <summary>
    /// 考勤班次服务接口
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/OA/[controller]")]
    public class AttendanceClassController : ManagementBaseController
    {
        private readonly IAttendanceClassService attendanceClassService;

        public AttendanceClassController(IAttendanceClassService attendanceService)
        {
            this.attendanceClassService = attendanceService;
        }

        #region 创建班次
        /// <summary>
        /// 创建班次
        /// </summary>
        /// <response code="201">班次创建成功</response>
        /// <returns></returns>
        [HttpPost]
        [Log("创建班次")]
        [ProducesResponseType(typeof(AttendanceClassDto), 201)]
        public IActionResult Post([FromBody]AttendanceClassRequestDto attendanceClassRequestDto)
        {
            var result = this.attendanceClassService.Create(this.Admin, attendanceClassRequestDto);
            return Created(string.Format("api/v1/sim/OA/AttendanceClass/{0}", result.ClassId), result);
        }

        #endregion

        #region 删除
        /// <summary>
        /// 删除一条班次信息
        /// </summary>
        /// <param name="classId">指定的班次Id</param>
        /// <returns></returns>
        [HttpDelete("{class_id}")]
        [Log("删除一条班次信息")]
        public IActionResult Delete([FromRoute(Name = "class_id")] long classId)
        {
            return Ok(this.attendanceClassService.Delete(this.Admin, classId));
        }
        #endregion

        #region 修改
        /// <summary>
        /// 修改班次信息
        /// </summary>
        /// <param name="classId">指定的班次Id</param>
        /// <param name="attendanceClassRequestDto">班次修改信息</param>
        /// <returns></returns>
        /// <response code="200">修改后的班次信息。</response>
        [HttpPut("{class_id}")]
        [Log("修改班次信息")]
        [ProducesResponseType(typeof(AttendanceClassDto), 200)]
        public IActionResult Put([FromRoute(Name = "class_id")] long classId, [FromBody]AttendanceClassRequestDto attendanceClassRequestDto)
        {
            return this.Ok(this.attendanceClassService.Update(this.Admin, classId, attendanceClassRequestDto));
        }

        #endregion

        /// <summary>
        /// 获取一条班次信息
        /// </summary>
        /// <param name="classId">指定的班次Id</param>
        /// <returns></returns>
        [HttpGet("{class_id}")]
        [ProducesResponseType(typeof(AttendanceClassDto), 200)]
        public IActionResult Get([FromRoute(Name = "class_id")] long classId)
        {
            return Ok(this.attendanceClassService.GetAttendanceClassByClassId(classId));
        }

        /// <summary>
        /// 考勤班次列表
        /// </summary>
        /// <param name="className">班次名称</param>
        /// <param name="pageIndex">起始页</param>
        /// <param name="pageSize">分页数</param>
        /// <param name="ascending">是否升序排序</param>
        /// <response code="200">数据查询成功。</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<AttendanceClassDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "class_name")]string className,
            [FromQuery(Name = "ascending")]bool ascending = true,
            int pageIndex = 1,
            int pageSize = 10)
        {
            var data = attendanceClassService.GetList(ascending, pageIndex, pageSize, className);
            return Ok(data);
        }
    }
}